<template>
	<view class='container bg-w'>
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="安全资讯">
				<template slot='left'>
					<view class="flex width-100">
						<i class='iconfont iconfanhui' @click='goBackApplication()'></i>
					</view>
				</template>
			</uni-nav-bar>
		</view>
		<view class="SafeConsult position-r-top">
			<uni-list>
			    <uni-list-item v-for="(item,index) in findSafeList" link @click="goConsultationDetails(item)">
						<template slot='header'>
							<view class="flex flex-between">
								<text class="wid-80 txtCut1">{{item.noticeTitle}}</text>
								<!-- <text class="color-6">{{item.noticeName}}</text> -->
							</view>
							<view class="html-style color-6 margin-t-5"v-html="item.introduction">
							</view>
						</template>
					</uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	import { findSafe } from '@/common/api/SafeConsult.js'
	import { equipmentTypeAll } from '@/common/api/api.js'
	export default {
		data() {
			return {
				page:{
					pageNo:1,
					pageSize:20
				},
				total: 0, //总条数
				totalPage: 0, //总页数
				findSafeList:[],
				noticeType:[]
			}
		},
		onShow() {
			uni.removeStorageSync('ConsultationData')
			equipmentTypeAll('notice_type').then(res => {
				this.noticeType = res.data
			})
			this.findSafeList = [];
			this.findSafeAll();
		},
		methods: {
			findSafeAll(){
				findSafe(this.page).then(res => {
					this.totalPage = res.data.pages
					this.findSafeList = this.findSafeList.concat(res.data.records)
					this.findSafeList.forEach(obj => {
						this.noticeType.forEach(obj2 => {
							if(obj.noticeType == obj2.value){
								this.$set(obj,'noticeName',obj2.label)
							}
						})
					})
				})
			},
			onReachBottom() { //上拉加载更多
				this.page.pageNo++
				if (this.page.pageNo <= this.totalPage) {
					this.findSafeAll();
				}
			},
			onPullDownRefresh(){//下拉刷新
				this.page.pageNo = 1;
				this.findSafeList = [];
				this.findSafeAll();
				setTimeout(function () {
						uni.stopPullDownRefresh();
				}, 1000);
			},
			goBackApplication(){
				uni.switchTab({
					url:'/pages/Application/Application'
				})
			},
			goConsultationDetails(item){
				uni.setStorageSync('ConsultationData',item)
				uni.navigateTo({
					url:'/pages/Application/SafeConsult/ConsultationDetails/ConsultationDetails'
				})
			},
		}
	}
</script>

<style>
 .SafeConsult /deep/ .uni-list-item__container{
	 display: block;
 }
	.html-style >>> p{width: 100%;font-size: 32rpx;line-height: 50rpx;color: #666;}
	.html-style >>> img{width: 100%;height: 360rpx;margin: 20rpx 0;border: 1px solid #eee;box-sizing: border-box;display: none;}
</style>
